package com.zhongshengnetwork.rightbe.view.controller;

import android.content.Context;
//import android.databinding.DataBindingUtil;
//import android.databinding.ViewDataBinding;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;

import com.pj.core.BaseActivity;
import com.pj.core.viewholders.ViewHolder;

/**
 * Created by luzhenwen on 2018/10/19.
 */

public abstract class BindingViewController<T extends ViewDataBinding, K, B, P> implements ViewController<K, B, P> {

    protected T mBinding;

    public BindingViewController(T binding) {
        mBinding = binding;
        onBind(binding);
    }

    public BindingViewController(View view) {
        this((T) DataBindingUtil.bind(view));
    }

    public BindingViewController(Context context, int layout, ViewGroup parent) {
        this((T) DataBindingUtil.inflate(LayoutInflater.from(context), layout, parent, false));
    }

    public T getBinding() {
        return mBinding;
    }

    protected abstract void onBind(T binding);

    public void assignClickListener(View.OnClickListener listener, View... views) {
        for (View v : views) {
            v.setOnClickListener(listener);
        }
    }
}
